//
//  AppendFishpondTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/22.
//

#import "AppendFishpondTableViewCell.h"

#import "YTBaseSelectStringView.h"
#import "YTBaseEditorStringView.h"
@interface AppendFishpondTableViewCell ()<UITextFieldDelegate>


@property (nonatomic ,strong) UILabel * Nolab;
@property (nonatomic ,strong) UITextField * nameLab;
@property (nonatomic ,strong) UILabel * tissueNameLab;
@property (nonatomic ,strong) UITextField * expectYield;


@end
@implementation AppendFishpondTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = KcolorHex(@"#ECEDEE");
    self.contentView.clipsToBounds = YES;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    MJWeakSelf
    UIView * bgview = [UIView new];
    bgview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJBK:kwt(0) andView:bgview andWidth:0.5 andColor:KcolorHex(@"#E5E3E3")];
    [self.contentView addSubview:bgview];
    [bgview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.offset(kwt(-10));
        make.bottom.offset(kwt(10));
    }];
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#DDDDDD");
    [bgview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(kwt(10));
        make.height.offset(0.5);
    }];
    UIView * oneline = [UIView new];
    oneline.backgroundColor = KcolorHex(@"#E5E3E3");
    [bgview addSubview:oneline];
    [oneline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(50));
        make.bottom.top.offset(0);
        make.width.offset(0.5);
    }];
    
    UILabel * onelab = [DTKTool labelWithText:@"1" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    self.Nolab = onelab;
    [bgview addSubview:onelab];
    [onelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.equalTo(oneline.mas_left);
        make.centerY.offset(0);
    }];
    
    UIView * tweline = [UIView new];
    tweline.backgroundColor = KcolorHex(@"#E5E3E3");
    [bgview addSubview:tweline];
    [tweline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(134));
        make.bottom.top.offset(0);
        make.width.offset(0.5);
    }];
    
    UITextField * nameLab = [UITextField new];
    nameLab.delegate = self;
    nameLab.textColor = KcolorHex(@"#222222");
    nameLab.font = kFont(15);
    self.nameLab = nameLab;
    nameLab.attributedPlaceholder =  [DTKTool AttributedStringWithStr:@"请填写" andNodeColor:KcolorHex(@"#787A79") andSeledColor:KcolorHex(@"#787A79") andFont:kFont(15) andPattenr:@"[*]"];
    [bgview addSubview:nameLab];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(oneline.mas_right).offset(kwt(8));
        make.right.equalTo(tweline.mas_left).offset(kwt(-8));
        make.centerY.equalTo(onelab);
    }];
    
    UIView * threeline = [UIView new];
    threeline.backgroundColor = KcolorHex(@"#E5E3E3");
    [bgview addSubview:threeline];
    [threeline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(266));
        make.bottom.top.offset(0);
        make.width.offset(0.5);
    }];
    
    UIImageView * upimg = kimageView(@"tangkou_expand");
    [bgview addSubview:upimg];
    [upimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(kwt(15));
        make.right.equalTo(threeline.mas_left).offset(kwt(-8));
        make.centerY.equalTo(onelab);
    }];
    upimg.addClickBlock(^{
        [weakSelf openTKMZ];
    });
    
    UILabel * tissueNameLab = [DTKTool labelWithText:@"请选择" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    [bgview addSubview:tissueNameLab];
    self.tissueNameLab = tissueNameLab;
    [tissueNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tweline.mas_right).offset(kwt(8));
        make.right.equalTo(upimg.mas_left).offset(kwt(-8));
        make.centerY.equalTo(onelab);
    }];
    tissueNameLab.addClickBlock(^{
        [weakSelf openTKMZ];
    });
    
    
    
    
    UITextField * expectYield = [UITextField new];
    self.expectYield = expectYield;
    expectYield.delegate = self;
    expectYield.textColor = KcolorHex(@"#222222");
    expectYield.font = kFont(15);
    expectYield.keyboardType = UIKeyboardTypeDecimalPad;
    expectYield.attributedPlaceholder =  [DTKTool AttributedStringWithStr:@"请填写" andNodeColor:KcolorHex(@"#787A79") andSeledColor:KcolorHex(@"#787A79") andFont:kFont(15) andPattenr:@"[*]"];
    [bgview addSubview:expectYield];
    [expectYield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(threeline.mas_right).offset(kwt(8));
        make.right.offset(kwt(-8));
        make.centerY.equalTo(onelab);
    }];
   
    
    
  
}
- (void)openTKMZ{
    if(self.openTKMZBlock){
        self.openTKMZBlock(self.model);
    }
}
- (void)setIndex:(int)Index{
    self.Nolab.text = [NSString stringWithFormat:@"%d",Index];
}
- (void)setModel:(addPondModelListModel *)model{
    _model = model;
    self.nameLab.text = model.name;
    
    if(model.tissueName.length > 0){
        self.tissueNameLab.text = model.tissueName;
        self.tissueNameLab.textColor = KcolorHex(@"#222222");
    } else {
        self.tissueNameLab.text = @"请选择";
        self.tissueNameLab.textColor = KcolorHex(@"#787A79");
    }
    self.expectYield.text = model.expectYield;

}

-(void)textFieldDidEndEditing:(UITextField *)textField{
    if(textField == self.nameLab){
        self.model.name = textField.text;
    } else if(textField == self.expectYield){
        self.model.expectYield = textField.text;
    }
}
@end
